using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AudioMgr : SingletonMono<AudioMgr>
{
    [SerializeField] public AudioSource bgmSource, fxSource;

    [SerializeField]
    private AudioClip levelFail,
                      singlePoint,
                      collected,
                      boom,
                      levelVictory;
    [SerializeField]
    private AudioClip MainMenuBgm,
                       BGM02,
                       BGM03;


    public float BgmVolumn
    {
        get => bgmSource.volume;
        set => bgmSource.volume = Mathf.Clamp01(value);
    }

    public bool IsBgmPlaying => bgmSource.isPlaying;

    public void PlayBgm() => bgmSource.UnPause();

    public void PauseBgm() => bgmSource.Pause();


    protected override void OnInstanceAwake()
    {
        DontDestroyOnLoad(this);
        //bgmSource.Play();
    }


    public float FxVolumn
    {
        get => fxSource.volume;
        set => fxSource.volume = Mathf.Clamp01(value);
    }


    public void PlayFx(AudioFxType fx)
    {
        fxSource.Stop();
        fxSource.clip = fx switch
        {
        AudioFxType.LevelFail => levelFail,
        AudioFxType.Boom => boom,
        AudioFxType.Collected => collected,
        AudioFxType.LevelVictory => levelVictory,
        AudioFxType.SinglePoint => singlePoint,

            _ => null
        };
        fxSource.Play();
    }


    public void PlayGameBgm(AudioBgmType bgm)
    {
        bgmSource.Stop();
        bgmSource.clip = bgm switch
        {

            AudioBgmType.MainMenuBgm => MainMenuBgm,
            AudioBgmType.BGM02 => BGM02,
            AudioBgmType.BGM03 => BGM03,
            _ => null
        };
        bgmSource.Play();
    }
}


public enum AudioFxType
{

    //
    LevelFail,
    SinglePoint,
    Collected,
    Boom,
    LevelVictory


}
public enum AudioBgmType
{
    MainMenuBgm,
    BGM02,
    BGM03
}